<html>
<head><meta charset="utf-8"><title>Diagnostics from inside proc macros are broken · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics.20from.20inside.20proc.20macros.20are.20broken.html">Diagnostics from inside proc macros are broken</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218606229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics%20from%20inside%20proc%20macros%20are%20broken/near/218606229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics.20from.20inside.20proc.20macros.20are.20broken.html#218606229">(Dec 02 2020 at 19:24)</a>:</h4>
<p><a href="/user_uploads/4715/ODisrHZ48O3VFT66QSUmKKmJ/screenshot-2020-12-02-202249.png">screenshot-2020-12-02-202249.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/ODisrHZ48O3VFT66QSUmKKmJ/screenshot-2020-12-02-202249.png" title="screenshot-2020-12-02-202249.png"><img src="/user_uploads/4715/ODisrHZ48O3VFT66QSUmKKmJ/screenshot-2020-12-02-202249.png"></a></div><p>It looks like diagnostics are attached to the outer file instead of the macro file? This is odd, it does not seem to happen with <code>macro_rules!</code> macros.</p>



<a name="218693207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics%20from%20inside%20proc%20macros%20are%20broken/near/218693207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics.20from.20inside.20proc.20macros.20are.20broken.html#218693207">(Dec 03 2020 at 13:39)</a>:</h4>
<p>This looks correct to me? <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="bp">self</span><span class="p">.</span><span class="n">source_map</span><span class="p">.</span><span class="n">diagnostics</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">BodyDiagnostic</span>::<span class="n">InactiveCode</span><span class="p">(</span><span class="n">InactiveCode</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">file</span>: <span class="nc">self</span><span class="p">.</span><span class="n">expander</span><span class="p">.</span><span class="n">current_file_id</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">node</span>: <span class="nc">SyntaxNodePtr</span>::<span class="n">new</span><span class="p">(</span><span class="n">owner</span><span class="p">.</span><span class="n">syntax</span><span class="p">()),</span><span class="w"></span>
<span class="w">    </span><span class="n">cfg</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">opts</span>: <span class="nc">self</span><span class="p">.</span><span class="n">expander</span><span class="p">.</span><span class="n">cfg_options</span><span class="p">().</span><span class="n">clone</span><span class="p">(),</span><span class="w"></span>
<span class="p">}));</span><span class="w"></span>
</code></pre></div>
<p>(from <a href="https://github.com/rust-analyzer/rust-analyzer/blob/5a1306a43652d914035b2cf0b703f4bfd3451a33/crates/hir_def/src/body/lower.rs#L923-L928">https://github.com/rust-analyzer/rust-analyzer/blob/5a1306a43652d914035b2cf0b703f4bfd3451a33/crates/hir_def/src/body/lower.rs#L923-L928</a>)</p>



<a name="218693689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics%20from%20inside%20proc%20macros%20are%20broken/near/218693689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics.20from.20inside.20proc.20macros.20are.20broken.html#218693689">(Dec 03 2020 at 13:43)</a>:</h4>
<p>Ah, it's a general issue with all diagnostics</p>
<p><a href="/user_uploads/4715/fARYw76ciq6AncsGnB5qRRKm/screenshot-2020-12-03-144337.png">screenshot-2020-12-03-144337.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/fARYw76ciq6AncsGnB5qRRKm/screenshot-2020-12-03-144337.png" title="screenshot-2020-12-03-144337.png"><img src="/user_uploads/4715/fARYw76ciq6AncsGnB5qRRKm/screenshot-2020-12-03-144337.png"></a></div>



<a name="218729163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics%20from%20inside%20proc%20macros%20are%20broken/near/218729163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics.20from.20inside.20proc.20macros.20are.20broken.html#218729163">(Dec 03 2020 at 17:44)</a>:</h4>
<p>Found the problem, and opened a fix here: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/6712">https://github.com/rust-analyzer/rust-analyzer/pull/6712</a></p>



<a name="218729202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics%20from%20inside%20proc%20macros%20are%20broken/near/218729202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics.20from.20inside.20proc.20macros.20are.20broken.html#218729202">(Dec 03 2020 at 17:45)</a>:</h4>
<p>Haven't found an easy way to add a test though</p>



<a name="218729283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics%20from%20inside%20proc%20macros%20are%20broken/near/218729283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Diagnostics.20from.20inside.20proc.20macros.20are.20broken.html#218729283">(Dec 03 2020 at 17:45)</a>:</h4>
<p>Maybe we should start writing a couple of "quick" proc macro tests that use only the <code>proc_macro_test</code> crate</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>